#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/stat.h>
#include "restart.h"

#define FIFO_PERMS (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)

int main (int argc, char *argv[])
{
   int i, n;

   if (argc != 3)
   {
      fprintf(stderr, "Usage: %s barrier_name processes\n", argv[0]);
      return 1;
   }
   n = atoi(argv[2]);
   char* requestpipe = malloc(strlen(argv[1]) + 8);
   char* releasepipe = malloc(strlen(argv[1]) + 8);
   strcpy(requestpipe, argv[1]);
   strcpy(releasepipe, argv[1]);
   strcat(requestpipe,".request");
   strcat(releasepipe,".release");
   if(mkfifo(requestpipe, FIFO_PERMS) == -1)
      perror("Failed to create request pipe");
   if(mkfifo(releasepipe, FIFO_PERMS) == -1)
      perror("Failed to create release pipe");
   
   int requestfd;
   if ((requestfd = r_open2(requestpipe, O_RDWR)) == -1)
   {
      perror("Server failed to open its request pipe");
      return 1;
   }
   r_dup2(requestfd, STDOUT_FILENO);

}
